package com.example.kotlin.basis

/**
 * Created by xiao_tan on 17/7/23.
 * 默认参数和具名参数
 */


//获取长方形的面积
fun getRectArea(l: Float, w: Float): Float {
    return l * w;
}

val Pi = 3.14159f
//获取圆的周长
fun getRectPerimeter(PI: Float = com.example.kotlin.basis.Pi, r: Float): Float {
    return 2 * PI * r;
}

//获取圆的周长,设置默认参数
fun getRectPerimeter2(PI: Float = com.example.kotlin.basis.Pi, d: Float): Float {
    return PI * d;
}

//获取圆柱体的体积
fun getRectVolume(PI: Float = com.example.kotlin.basis.Pi, r: Float, h: Float): Float {
    return PI * r * r * h
}

//获取球体的表面积
fun getSphereSurfaceArea(PI: Float = com.example.kotlin.basis.Pi, r: Float): Float {
    return PI * r * r * 4
}

fun main(args: Array<String>) {

    println(com.example.kotlin.basis.getRectArea(3.0f, 5f))
    println(com.example.kotlin.basis.getRectPerimeter(r = 2f))//具名参数使用
    println(com.example.kotlin.basis.getRectPerimeter2(d = 4f))
    println(com.example.kotlin.basis.getRectVolume(r = 2f, h = 3f))
    println(com.example.kotlin.basis.getSphereSurfaceArea(r = 2f))
}